﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style type="text/css">
    .topPanel .search .input-group .form-control {
        padding: 4px 5px !important;
        height: 22px !important;
        margin: 0 10px !important;
        width: 80%;
    }

   .zdyPanel {
        height: 50px;
        line-height: 50px;
        background-color: #fff;
        border-top: 1px solid #ddd;
        border-left: 1px solid #ddd;
        border-right: 1px solid #ddd;
        margin: 0px;
        float: left;
        width: 100%;
    }
    .zdyTool {
        float: left;
        padding-left: 10px;
        width:100%;
    }
    .zdyBar {        
        height: 50px;
        line-height: 50px;
        padding: 0px;
        width: 100px;
        margin:0px;
    }

    .zdyUL{
        list-style-type:none;
        margin:5px 0px 0px -3px;
        padding:0px;
    }
    .zdyUL li{
        float:left;
        list-style:none;
        height:24px;
        line-height:22px;
    }
    .zdyUL li a {
        cursor:pointer;
        padding:5px 10px;
        border-radius:4px;
    }
    .zdyUL li i{
        margin-right:4px;
        font-size:13px;
        color:#666;
        vertical-align:middle;
        margin-top:-1px;
    }
    .zdyUL li a:hover{
        text-decoration: none;
        background-color: #1ABC9C;
        color:#fff;
    }
    .zdyGirdPanel {
        width:100%;
        margin:0px;
        padding:0px;
        float:left;
    }
    .zdyContentPanel {
        width:100%;
        margin:5px 0px 0px 0px;
        padding:0px;
        float:left;
    }
    .zdyFont {
        padding-left:5px;
        color:#ff6a00;
    }
</style>
<script type="text/javascript">
    var resultData;
    $(function () {       
        getItemList();
        gridList();                 
    });
    var selectPage = -1;
    var childPage = -1;
    function gridListRecord(pagerindex) {
        var $gridList = $("#gridListRecord");
        var rowobj = $("#gridList").jqGridRowValue()[pagerindex];
        var queryJson = {
            F_FarthId: rowobj == undefined?"": rowobj["F_Id"]
        };
        $gridList.dataGrid({
            url: "/MyTask/MyCustomerInfo/GetClientHistoryRecord", 
            postData: { queryJson: JSON.stringify(queryJson) },
            height: 200,
            colModel: [
                { label: '客户名称', name: 'F_ClientName', width: 100, align: 'left' },  
                { label: '活动名称', name: 'F_ActivityName', width: 150, align: 'left' },
                { label: '活动类型', name: 'F_ActivityType', width: 150, align: 'left' },
                { label: '场地类型', name: 'F_SiteType', width: 150, align: 'left' },
                { label: '场地大小', name: 'F_SiteSize', width: 150, align: 'left' },                
                { label: '联系人', name: 'F_Contract', width: 150, align: 'left' },
                { label: '公司职位', name: 'F_PositionId', width: 80, align: 'left' },
                { label: '联系电话', name: 'F_Phone', width: 80, align: 'left' },     
                { label: '公司邮箱', name: 'F_Mail', width: 100, align: 'left' },
                { label: '活动状态', name: 'F_ActivityState', width: 150, align: 'left' },
                { label: '需求提交时间', name: 'F_LastModifyTime', width: 100, align: 'left' },
                { label: '', name: 'F_Id', hidden: true },
            ],
            pager: "#gridPagerRecord",
            rowList: [10, 20],
            viewrecords: true
        });  
    }    

    function gridListRecordReload() {
        var $gridList = $("#gridListRecord");
        var rowobj = $("#gridList").jqGridRowValue();
        var queryJson = {
            F_FarthId: rowobj["F_Id"]
        };
        $gridList.jqGrid('setGridParam', {
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }

    function gridList() {
        var $gridList = $("#gridList");       
        $gridList.dataGrid({
            url: "/MyTask/MyCustomerInfo/GetGridDataJson",
            postData: { },
            height: 310,
            colModel: [                
                { label: '客户名称', name: 'F_ClientName', width: 200, align: 'left' },               
                {
                    label: '所在城市', name: 'F_CityId', width: 150, align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.citys.length; i++) {
                            if (resultData.citys[i]["F_ItemCode"] == rowObject["F_CityId"]) {
                                return resultData.citys[i]["F_ItemName"];
                            } else {
                                return '';
                            }
                        }
                    }
                },
                {
                    label: '客户级别', name: 'F_ClientLevel', width: 150, align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.khdjs.length; i++) {
                            if (resultData.khdjs[i]["F_ItemCode"] == rowObject["F_ClientLevel"]) {
                                return resultData.khdjs[i]["F_ItemName"];
                            } else {
                                return '';
                            }
                        }
                    }
                },
                {
                    label: '客户类型', name: 'F_ClientType', width: 80, align: 'left', formatter: function (cellvalue, options, rowObject) {
                        for (var i = 0; i < resultData.khlxs.length; i++) {
                            if (resultData.khlxs[i]["F_ItemCode"] == rowObject["F_ClientType"]) {
                                return resultData.khlxs[i]["F_ItemName"];
                            } else {
                                return '';
                            }
                        }
                    }
                },               
                { label: '更新时间', name: 'F_LastModifyTime', width: 160, align: 'left' },                
                { label: '', name: 'F_Id', hidden: true },  
                {
                    label: '操作', name: '', align: 'left', width: 200, formatter: function (cellvalue, options, rowObject) {
                        return "<ul class=\"zdyUL\" style=\"white-space:nowrap;\"><li><a name=\"" + rowObject["F_Id"] + "\" authorize=\"yes\" onclick=\"btn_edit(this)\"><i class=\"fa fa-pencil-square-o\"></i>修改客户</a></li><li><a name=\"" + rowObject["F_Id"] + "\" authorize=\"yes\" onclick=\"btn_detail(this)\"><i class=\"fa fa-search-plus\"></i>查看客户</a></li></ul>";
                    }
                },
            ],
            pager: "#gridPager",
            rowNum: 10,
            rowList: [10, 20, 30],
            viewrecords: true,            
            ondblClickRow: function (rowid, iRow, iCol, e) {                
                gridindustryRecordReload();
                selectPage = rowid;
            },            
            loadComplete: function () {
                gridindustryRecord(0);                
            }
        });
    }

    function btn_detail(obj) {
        $.modalOpen({
            id: "ClientDetails",
            title: "客户信息",
            url: "/MyTask/MyCustomerInfo/Details?keyValue=" + obj.name,
            width: "1200px",
            height: "650px",
            btn: null
        });
    }

    function btn_add() {
        $.modalOpen({
            id: "ClientForm",
            title: "新增客户信息",
            url: "/MyTask/MyCustomerInfo/Form",
            width: "1200px",
            height: "650px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    function btn_edit(obj) {
        $.modalOpen({
            id: "ClientFormEdit",
            title: "编辑-客户信息",
            url: "/MyTask/MyCustomerInfo/Form?keyValue=" + obj.name,
            width: "1200px",
            height: "650px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });   
    }

    function btn_delete(obj) {
        $.deleteForm({
            url: "/MyTask/MyCustomerInfo/DeleteEntity",
            param: { keyValue: obj.name },
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        });
    }

    function getItemList() {
        $.ajax({
            url: "/MyTask/MyCustomerInfo/GetItemListJson",
            dataType: "json",
            async: false,
            success: function (data) {
                resultData = data;
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest);
                console.log(textStatus);
                console.log(errorThrown);
            }
        });
    }

    function btn_budget() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "ClientBudget",
            title: "客户预算",
            url: "/MyTask/MyCustomerInfo/Budget?keyValue=" + keyValue,
            width: "1200px",
            height: "650px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    function gridindustryRecordReload() {
        var $gridList = $("#gridindustryRecord");
        var rowobj = $("#gridList").jqGridRowValue();
        var queryJson = {
            F_FarthId: rowobj == undefined?"": rowobj["F_Id"]
        };
        $gridList.jqGrid('setGridParam', {
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }

    function gridindustryRecord(pagerindex) {
        var $gridList = $("#gridindustryRecord");
        var rowobj = $("#gridList").jqGridRowValue()[pagerindex];
        var queryJson = {
            F_FarthId: rowobj == undefined ? "" : rowobj["F_Id"]
        };        
        $gridList.dataGrid({
            url: "/MyTask/MyCustomerInfo/GetIndustryRecord",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: 315,
            colModel: [                
                { label: '客户名称', name: 'F_ClientName', width: 200, align: 'left' }, 
                {
                    label: '所属行业', name: 'F_IndustryId', width: 100, align: 'left', formatter: function (cellvalue, options, rowObject) {
                        var isok = false;
                        for (var i = 0; i < resultData.sshys.length; i++) {
                            if (resultData.sshys[i].F_Id == rowObject["F_IndustryId"]) {
                                isok = true;
                                return resultData.sshys[i]["F_ItemName"];
                            }
                        }
                        if (!isok) {
                            return '';
                        }
                    }
                },  
                { label: '品牌项目组', name: 'F_ProjectName', width: 200, align: 'left' }, 
                {
                    label: '活动类型', name: 'F_ActivityType', width: 100, align: 'left', formatter: function (cellvalue, options, rowObject) {
                        var isok = false;
                        for (var i = 0; i < resultData.ActivityType.length; i++) {
                            if (resultData.ActivityType[i].F_Id == rowObject["F_ActivityType"]) {
                                isok = true;
                                return resultData.ActivityType[i]["F_ItemName"];
                            } 
                        }  
                        if (!isok) {
                            return '';
                        }
                    }
                }, 
                {
                    label: '场地类型', name: 'F_SiteType', width: 100, align: 'left', formatter: function (cellvalue, options, rowObject) {
                        var isok = false;
                        for (var i = 0; i < resultData.SiteType.length; i++) {
                            if (resultData.SiteType[i].F_Id == rowObject["F_SiteType"]) {
                                isok = true;
                                return resultData.SiteType[i]["F_ItemName"];
                            } 
                        }
                        if (!isok) {
                            return '';
                        }
                    }
                }, 
                { label: '预算', name: 'F_ActivityBudget', width: 120, align: 'left' }, 
                { label: '联系人', name: 'F_Contract', width: 100, align: 'left' },  
                {
                    label: '所属部门', name: 'F_Department', width: 100, align: 'left', formatter: function (cellvalue, options, rowObject) {
                        var isok = false;
                        for (var i = 0; i < resultData.ssbms.length; i++) {
                            if (resultData.ssbms[i].F_Id == rowObject["F_Department"]) {
                                isok = true;
                                return resultData.ssbms[i]["F_ItemName"];
                            } 
                        }
                        if (!isok) {
                            return '';
                        }
                    }
                },  
                {
                    label: '职位', name: 'F_PositionId', width: 100, align: 'left', formatter: function (cellvalue, options, rowObject) {
                        var isok = false;
                        for (var i = 0; i < resultData.gszws.length; i++) {
                            if (resultData.gszws[i].F_Id == rowObject["F_PositionId"]) {
                                isok = true;
                                return resultData.gszws[i]["F_ItemName"];
                            } 
                        }
                        if (!isok) {
                            return '';
                        }
                    }
                },  
                { label: '联系电话', name: 'F_Phone', width: 100, align: 'left' },  
                { label: '邮箱', name: 'F_Mail', width: 150, align: 'left' },
                { label: '更新时间', name: 'F_LastModifyTime', width: 120, align: 'left' },
                { label: '', name: 'F_Id', hidden: true },
                {
                    label: '操作', name: 'F_Id', align: 'left', width: 360, formatter: function (cellvalue, options, rowObject) {
                        return "<ul class=\"zdyUL\" style=\"white-space:nowrap;\"><li><a name=\"" + rowObject["F_Id"] + "\" authorize=\"yes\" onclick=\"btn_editIndustry(this)\"><i class=\"fa fa-pencil-square-o\"></i>修改品牌项目组</a></li><li><a name=\"" + rowObject["F_Id"] + "\" authorize=\"yes\" onclick=\"btn_deleteIndustry(this)\"><i class=\"fa fa-trash-o\"></i>删除品牌项目组</a></li><li><a name=\"" + rowObject["F_Id"] + "\" authorize=\"yes\" onclick=\"btn_detailIndustry(this)\"><i class=\"fa fa-search-plus\"></i>查看品牌项目组</a></li></ul>";
                    }
                },
            ],
            ondblClickRow: function (rowid, iRow, iCol, e) {
                childPage = rowid;
            },
            pager: "#gridPagerindustry",
            rowNum: 10,
            rowList: [10],
            viewrecords: true
        });  
    }

    function btn_editIndustry(obj) { 
        var rowobj = $("#gridList").jqGridRowValue();
        var F_ClientId;
        if (selectPage == -1) {
            F_ClientId = rowobj[0].F_Id;
        } else {
            F_ClientId = rowobj["F_Id"];
        }
        $.modalOpen({
            id: "ClientTrackingEdit",
            title: "编辑-行业(品牌)项目组",
            url: "/MyTask/MyCustomerInfo/ProjectForm?F_ClientId=" + F_ClientId + "&keyValue=" + obj.name,
            width: "1200px",
            height: "650px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });  
    }

    function btn_addIndustry() {
        var rowobj = $("#gridList").jqGridRowValue();
        if (selectPage == -1) {
            $.modalOpen({
                id: "ClientTracking",
                title: "新建-行业(品牌)项目组",
                url: "/MyTask/MyCustomerInfo/Project?F_ClientId=" + rowobj[0].F_Id + "&keyValue=",
                width: "1200px",
                height: "650px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();                   
                }
            });
        } else {
            $.modalOpen({
                id: "ClientTracking",
                title: "新建-行业(品牌)项目组",
                url: "/MyTask/MyCustomerInfo/Project?F_ClientId=" + rowobj["F_Id"] +"&keyValue=",
                width: "1200px",
                height: "650px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();                    
                }
            });
            
        }            
    }

    function btn_deleteIndustry(obj) {
        $.deleteForm({
            url: "/MyTask/MyCustomerInfo/DeleteProjectEntity",
            param: { keyValue: obj.name },
            success: function () {
                $.currentWindow().$("#gridindustryRecord").trigger("reloadGrid");
            }
        });
    }

    function btn_detailIndustry(obj) {
        $.modalOpen({
            id: "ClientTrackingEdit",
            title: "查看-品牌项目组",
            url: "/MyTask/MyCustomerInfo/ProjectDetails?keyValue=" + obj.name,
            width: "1200px",
            height: "650px",            
            btn: null,
        }); 
    }
</script>
<div class="zdyContentPanel" style="height:25px;line-height:25px;background-color:#eee;border:1px solid #ddd;margin-bottom:2px;">
    <span class="zdyFont">操作说明：上下表格行数据联动，请双击！</span>
</div>
<div class="zdyPanel">
    <div class="zdyTool">        
        <div class="zdyBar" style="float:right;white-space:nowrap;width:180px;">
            <div class="btn-group">
                <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
            </div>
            <div class="btn-group">
                <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-eraser"></i>新建客户</a>
            </div>
        </div>
    </div>
</div>
<div class="zdyGirdPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
<div class="zdyContentPanel">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#industryRecord" data-toggle="tab">行业(品牌方)项目组</a></li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane fade in active" id="visitRecord">
            <div class="zdyPanel" style="margin-top:3px;">
                <div class="zdyTool">                    
                    <div class="zdyBar" style="float:right;white-space:nowrap;width:170px;">
                        <div class="btn-group">
                            <a id="NF-addIndustry" class="btn btn-primary dropdown-text" authorize="yes" onclick="btn_addIndustry()"><i class="fa fa-eraser"></i>新建品牌项目组</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="zdyGirdPanel">
                <table id="gridindustryRecord"></table>
                <div id="gridPagerindustry"></div>
            </div>
        </div>        
    </div>
</div>